package day8.homeworkII;

import java.io.*;

public class Task3 {
    public static void main(String[] args) throws IOException {
        String file = "C:\\Users\\shendiaosi\\Pictures\\电脑壁纸\\海贼王.jpg";
        String file2 = "C:\\Users\\shendiaosi\\Pictures\\Saved Pictures\\复制的.jpg";

        copy(new File(file), new File(file2));

    }

    public static void copy(File file, File file2) throws IOException {


        try(FileInputStream fis = new FileInputStream(file);
            FileOutputStream fos = new FileOutputStream(file2);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            BufferedInputStream bis = new BufferedInputStream(fis);
            ) {
            int n= 0;

            while((n=bis.read())!=-1) { //将图片读出存入缓存区
                bos.write(n);  //图片写入缓存区
            }
        } catch (IOException E){
            E.printStackTrace();
        }
    }
}
